package com.ehotting.edsta.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ehotting.eaf.core.domain.R;
import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.eaf.security.annotation.InnerAuth;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.eaf.security.annotation.PreAuthorize;
import com.ehotting.eaf.core.domain.system.api.AppVersion;
import com.ehotting.edsta.system.service.IAppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * C端软件版本管理Controller
 * 
 * @author edsta
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/version")
public class AppVersionController extends BaseController
{
    @Autowired
    private IAppVersionService appVersionService;

    /**
     * 查询C端软件版本管理列表
     */
    @PreAuthorize(hasPermi = "edsta:version:list")
    @GetMapping("/list")
    public TableDataInfo list(AppVersion appVersion)
    {
        startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        return getDataTable(list);
    }

    /**
     * 导出C端软件版本管理列表
     */
    @PreAuthorize(hasPermi = "edsta:version:export")
    @Log(title = "C端软件版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppVersion appVersion) throws IOException
    {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        util.exportExcel(response, list, "C端软件版本管理数据");
    }

    /**
     * 获取C端软件版本管理详细信息
     */
    @PreAuthorize(hasPermi = "edsta:version:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appVersionService.selectAppVersionById(id));
    }

    /**
     * 新增C端软件版本管理
     */
    @PreAuthorize(hasPermi = "edsta:version:add")
    @Log(title = "C端软件版本管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppVersion appVersion)
    {
        return toAjax(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改C端软件版本管理
     */
    @PreAuthorize(hasPermi = "edsta:version:edit")
    @Log(title = "C端软件版本管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppVersion appVersion)
    {
        return toAjax(appVersionService.updateAppVersion(appVersion));
    }

    /**
     * 删除C端软件版本管理
     */
    @PreAuthorize(hasPermi = "edsta:version:remove")
    @Log(title = "C端软件版本管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appVersionService.deleteAppVersionByIds(ids));
    }

    /**
     * @return
     */
    @InnerAuth
    @RequestMapping(value = "/getLatestInfo",method = RequestMethod.GET)
    public R<AppVersion> getLatestInfo(String platform){
        return R.ok(appVersionService.getLatestInfo(platform));
    }
}
